package com.gxuwz.attend.service.Impl;

import com.gxuwz.attend.dao.UserDao;
import com.gxuwz.attend.entity.User;
import com.gxuwz.attend.service.UserService;

import java.util.List;

public class UserServiceImpl implements UserService {

    private UserDao userDao;

    public void setUserDao(UserDao userDao) {

        this.userDao = userDao;
    }

    /**
     * 登录
     * @param fullname
     * @param password
     * @return
     */
    @Override
    public boolean query(String fullname, String password){
        boolean flag = false;
        User user = new User();
        user.setPassword(password);
        user.setFullname(fullname);
        List<User> userList= userDao.query(user);
        flag = !userList.isEmpty();
        return flag;
    }

    /**
     * 模糊查询数据
     * @param user
     * @return
     */
    @Override
    public List<User> queryUsers(User user){
        List<User> userList=null;
        userList=userDao.query(user);
        return  userList;

    }
    @Override
    public User queryUser(User user, String id){
        List<User> userList=null;
        userList=userDao.query(user);
        if (userList!=null){
            user=userList.get(0);
        }
        return  user;
    }
    /**
     * 模糊查询数据
     * @return
     */
    @Override
    public List<User> getUsers(){
        List<User> userList=null;
        userList=userDao.getUsers();
        return  userList;

    }
    /**
     * 根据userid查询用户数据
     * @param userid
     * @return
     */
/*    public User queryUser(String userid){
        User user=new User();
        user.setUserid(userid);
        return  userDao.query(user);

    }*/

    /**
     * 添加数据
     * @param user
     */
    @Override
    public void insertUser(User user){
        userDao.insert(user);
    }

    /**
     * 更新数据
     * @param user
     */
    @Override
    public void updateUser(User user){
        userDao.update(user);
    }

    /**
     * 删除数据
     * @param userid
     */
    @Override
    public void deleteUser(String userid){
        userDao.delete(userid);
    }

}
